package com.jinzhi.jzweb.controller;


import java.util.*;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazSignupItemDO;
import com.jinzhi.jzweb.service.JazSignupItemService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 报名项目表
 * </pre>
 * <small> 2024-09-05 15:21:59 | Long</small>
 */
@Controller
@RequestMapping("/jzweb/jazSignupItem")
public class JazSignupItemController extends BaseController {
	@Autowired
	private JazSignupItemService jazSignupItemService;
	
	@GetMapping()
	//@RequiresPermissions("jzweb:jazSignupItem:jazSignupItem")
	String JazSignupItem(){
	    return "jzweb/jazSignupItem/jazSignupItem";
	}
	
	@ResponseBody
	@GetMapping("/list")
//	@RequiresPermissions("jzweb:jazSignupItem:jazSignupItem")
	public Result<List<JazSignupItemDO>> list(Long groupId){
		// 查询列表数据
		List<JazSignupItemDO> jazSignupItemDOS = jazSignupItemService.selectList(new EntityWrapper<JazSignupItemDO>()
				.eq("group_id",groupId));
		return Result.ok(jazSignupItemDOS);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazSignupItem:add")
	String add(){
	    return "jzweb/jazSignupItem/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazSignupItem:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazSignupItemDO jazSignupItem = jazSignupItemService.selectById(id);
		model.addAttribute("jazSignupItem", jazSignupItem);
	    return "jzweb/jazSignupItem/edit";
	}
	
	@Log("添加报名项目表")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazSignupItem:add")
	public Result<String> save( JazSignupItemDO jazSignupItem){
		jazSignupItemService.insert(jazSignupItem);
        return Result.ok();
	}
	
	@Log("修改报名项目表")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazSignupItem:edit")
	public Result<String>  update( JazSignupItemDO jazSignupItem){
		boolean update = jazSignupItemService.updateById(jazSignupItem);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除报名项目表")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazSignupItem:remove")
	public Result<String>  remove( Long id){
		jazSignupItemService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除报名项目表")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazSignupItem:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazSignupItemService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
